package com.qc.blogsystemplus.mapper;

import com.qc.blogsystemplus.bean.DiscussBean;
import com.qc.blogsystemplus.entity.Discuss;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface DiscussMapper {

    @Select("SELECT discuss.id,content,username,discuss.article_id FROM discuss,`user` WHERE discuss.user_id = `user`.id AND discuss.article_id = #{article_id} ")
    List<Discuss> getDiscuss(int article_id);

    @Select("SELECT discuss.id,content,username,discuss.article_id FROM discuss,`user` WHERE discuss.user_id = `user`.id ")
    List<Discuss> getAllDiscuss();

    @Insert("INSERT INTO discuss (content,user_id,article_id) VALUES(#{content},#{user_id},#{article_id})")
    int addDiscuss(DiscussBean discussBean);

    @Delete("DELETE FROM discuss WHERE id = #{id}")
    int delDeiscuss(DiscussBean discussBean);

    @Update("UPDATE discuss SET good_num = good_num+1 WHERE id = #{id}")
    int addGood(DiscussBean discussBean);
}
